package com.diors.game.engine.arpg.npc;

import java.util.List;

import org.apache.log4j.Logger;

import com.diors.game.engine.arpg.npc.NpcFacotry.NpcAdapter;
import com.diors.game.engine.arpg.npc.entity.NpcEntity;
import com.diors.game.engine.arpg.npc.model.NpcBornModel;
import com.diors.game.engine.arpg.scene.entity.MapEntity;
import com.diors.game.engine.arpg.scene.entity.SceneEntity;

/**
 * NPC引擎
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-26
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
public class NpcEngine 
{
	final static Logger log = Logger.getLogger(NpcEngine.class);  

	final static NpcManager npcManager = new NpcManager(); 
	
	/**
	 * 加载NPC
	 * @param scene		场景实体
	 * @param map		分线地图实体
	 * @param bornList	初始点列表
	 * @create	2013-10-28	darren.ouyang
	 */
	public static void loadNpcs (SceneEntity scene, MapEntity map, List<NpcBornModel> bornList)
	{
		for (NpcBornModel born : bornList)
		{
			NpcAdapter adapter = new NpcAdapter();
			adapter.setModel(born.getNpcModel());
			adapter.setX(born.getX());
			adapter.setY(born.getY());
			adapter.setD(0);
			adapter.setScene(scene);
			adapter.setLine(map);
			NpcEntity npc = NpcFacotry.createNpc(adapter);
			if (npc == null)
			{
				/*log.warn(new StringBuilder("场景加载NPC为NULL--场景ID[").append(scene.getID()).
						append("]场景原型[").append(scene.getBaseID()).append("]adapter[").
						append(adapter).append("]").toString());*/
				continue;
			}
			
			/* 注册NPC并注册到场景中 */
			npcManager.register(npc);
			registerMap(scene, map, npc);
		}
	}
	
	private static void registerMap (SceneEntity scene, MapEntity map, NpcEntity npc)
	{
		/*map.getNpcs().put(npc.getId(), npc);
		ScreenEntity screen = SceneEngine.getScreen(map, npc);
		screen.putNpc(npc);*/
	}
	
	/*public static void unregisterNpc (MapEntity map, NpcEntity npc)
	{
		map.getNpcs().put(npc.getId(), npc);
	}*/
	
	
}
